/***
*
*一个用于实现解析geojson的库geojson.js
*
*Daniel
*
*2018.08.23
*
***/
define(function(){
    
    var scope;
    var Geojson =function(){
        scope = this;
        this.height = 0;
        this.close = false;     //孔洞外剪切还是内剪切，默认内剪切Fals
    };
    Geojson.prototype.parse = function(project,height,close){
        var pro = parse(project);
        if(pro == undefined)return;
        var closed = close || scope.close;
        if(height !== undefined) scope.height = height;
        var simpleShapes = pro.toShapes(closed);
        for ( var j = 0; j < simpleShapes.length; j ++ ) {
            var simpleShape = simpleShapes[ j ];
            var shape3d = new THREE.ExtrudeBufferGeometry( simpleShape, {
                amount:  scope.height,
                bevelEnabled: false
            } );
            return shape3d
        }
    };
    function parse (path) {
        if( !path instanceof Array)return;
        var i = 0;
        var len = path.length;
        var PathGeo = new THREE.ShapePath();
        for(;i<len; i++) {
            var pro = path[i];
            if (pro.length>2) {
                for (var j = 0; j < pro.length; j++) {
                    var data = pro[j];
                    dataprase(PathGeo,data,j);
                }
            }
            else {
                dataprase(PathGeo,pro,i);
            }
        }
        function dataprase(geo,arr,flag){
            var data = arr;
            var x = data[0] * 0.001;
            var y = data[1] * 0.001;
            if (flag == 0) {
                geo.moveTo(x, y);
            } else {
                geo.lineTo(x, y);
            }
        }
        return PathGeo;
    }
    return Geojson;
    
});